class Solution {
public:
    int maxProduct(vector<int>& nums) {
        int n=nums.size();
        vector<int> Maxf(n,INT_MIN),Minf(n,INT_MAX);
        Maxf[0]=nums[0];
        Minf[0]=nums[0];
        int res=nums[0];
        for(int i=1;i<n;i++){
            Maxf[i]=max(nums[i],max(Maxf[i-1]*nums[i],Minf[i-1]*nums[i]));
            Minf[i]=min(nums[i],min(Maxf[i-1]*nums[i],Minf[i-1]*nums[i]));
            res=max(res,Maxf[i]);
        }
        return res;
    }
};
